package jp.co.mclnet.sample;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Iterator;

import jp.co.mclnet.dao.JdbcDaoImpl;
import jp.co.mclnet.saturday.dto.PersonalDto;
import jp.co.mclnet.saturday.dto.form.AllInOneDtoForm;

public class Sample4JdbcDao {

    private static final String JDBC_PASSWORD = "";
    private static final String JDBC_URL = ""
            + "jdbc:mysql://localhost:3306/saturday?autoReconnect=true&amp;"
            + "useUnicode=true&amp;characterEncoding=utf-8";
    private static final String JDBC_USERNAME = "root";

    public static void main(String[] args) throws Exception {
        JdbcDaoImpl dao = new JdbcDaoImpl("personal");

        PersonalDto dto = new AllInOneDtoForm();
        dto.setPersonalId("aaaa");
        PersonalDto condition = new AllInOneDtoForm();
        condition.setPersonalName("BBBB base");

        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME,
                    JDBC_PASSWORD);
            dao.setConnection(conn);
            dao.readByKey(dto);
            System.out.println(dto.getPersonalId());
            System.out.println(dto.getPersonalName());
            System.out.println(dto.getPersonalAddress());
            System.out.println(dto.getPersonalAge());
            System.out.println(dto.getPersonalEmail());

            Iterator<PersonalDto> it = dao.like(condition);
            while (it.hasNext()) {
                System.out.println(it.next().getPersonalId());
            }
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
    }
}
